package cj.web.admin.dao;
/*
 *  
 *  
*/
import java.util.List;
import java.util.Map;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.ReturnGeneratedKeys;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.admin.domain.VoteSubject;

/**
 * 
 * @author 
 *
 */
@DAO
public interface VoteSubjectDAO{
	
	@SQL("SELECT * FROM voteSubject WHERE deleteFlag=1 AND voteId=:t.voteId ORDER BY stickAt DESC,createAt ASC LIMIT :t.start,:t.length")
    List<Map> query(@SQLParam("t") VoteSubject voteSubject);
	
	@SQL("SELECT count(*) FROM voteSubject WHERE deleteFlag=1 AND voteId=:t.voteId ")
    int querysize(@SQLParam("t") VoteSubject voteSubject);
    
    @SQL("select * from voteSubject where id=:1")
    VoteSubject queryById(int id);
    
    @ReturnGeneratedKeys
    @SQL("INSERT INTO voteSubject (voteId,subject,isMutil,deleteFlag,createUser,createAt,updateUser,updateAt,count) VALUES (:1,:3,:2,1,:4,now(),:4,now(),:5)")
    int create(int voteId, int isMutil, String subject, String user,int count);
    
	@SQL("UPDATE voteSubject SET voteId=:2,subject=:4,isMutil=:3,updateUser=:5,updateAt=now(),count=:6 WHERE id=:1")
	void update(int subjectId, int voteId, int isMutil, String subject, String user, int count);
    
    @SQL("UPDATE voteSubject SET deleteFlag=0 WHERE id=:1")
    void deleteById(int id);
    
    @SQL("UPDATE voteSubject SET stickAt=now(),updateAt=now() WHERE id=:1")
	void updateByStickTime(int id);

    @SQL("UPDATE voteSubject SET stickAt=null,updateAt=now() WHERE id=:1")
	void updateByStickTimeIsNull(int id);

}